using UnityEngine;
using UnityEngine.UIElements;
using winS.UnityEditor.UIElement;
using Column = winS.UnityEditor.UIElement.Column;
using Label = winS.UnityEditor.UIElement.Label;

namespace winS.UnityEditor.GUI
{
    /// <summary>
    /// a box with title.
    /// </summary>
    public class Panel : VisualElement
    {
        public string title { get => label.text; set => label.text = value; }
        public TextAnchor titleAnchor { get => label.style.unityTextAlign.value; set => label.style.unityTextAlign = value; }

        public override VisualElement contentContainer { get; }

        private readonly Label label;

        protected internal Panel()
        {
            style.SetMargin(2f);
            style.overflow = Overflow.Hidden;
            style.SetBackgroundColor(ColorLevelUtility.GetColor(6));
            style.SetBorder(EditorElementUtility.defaultBorderColor, 1f, 4f);
            label = EditorElementUtility.elementFactory.CreateLabel(13f);
            Column column = EditorElementUtility.elementFactory.CreateColumn(label);
            hierarchy.Add(column);
            hierarchy.Add(contentContainer = new VisualElement());
            label.style.SetMarginLeft(4f);
            column.style.SetVerticalPadding(2f);
            column.style.SetBackgroundColor(ColorLevelUtility.GetColor(8));
            column.style.SetBorderBottom(1f, EditorElementUtility.defaultBorderColor);
            contentContainer.style.SetMargin(2f);
            contentContainer.style.flexGrow = 1f;
        }
    }
}